package com.shuma.loggingservice.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.Serializable;

@Configuration
public class LogMqConfig implements Serializable {

    public static final String EXCHANGE = "log.topic";
    public static final String ROUTING_KEY = "log.action";
    public static final String QUEUE = "log.queue";

    // 声明交换机（和 user-service 保持一致）
    @Bean
    public TopicExchange logExchange() {
        return new TopicExchange(EXCHANGE);
    }

    // 声明队列（消费者必须声明队列才能监听）
    @Bean
    public Queue logQueue() {
        return new Queue(QUEUE);
    }

    // 声明绑定（把队列绑定到交换机）
    @Bean
    public Binding logBinding() {
        return BindingBuilder.bind(logQueue()).to(logExchange()).with(ROUTING_KEY);
    }
}
